package com.wenhua.mail.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wenhua.mail.config.RespBean;
import com.wenhua.mail.service.MailService;

/**
 * @Description
 * @Author ycq
 * @Create 2020-03-31 10:05
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/v1")
public class MailController {

    @Autowired
    private MailService mailService;

    /**
     * 发送邮件接口
     *
     * @param to 接受者
     * @return
     * @throws Exception
     */
    @PostMapping("/sendMail")
    public RespBean sendMail(@RequestParam("to") String to) throws Exception {
        String verifyCode = mailService.sendHtmlMail(to);
        return RespBean.ok(verifyCode);
    }

    /**
     * 发送邮件接口带回调地址
     *
     * @param to  接受者
     * @param url 回调地址 对方点击此地址 进行跳转调用方系统 传什么就在邮件链接中返回什么
     * @return
     * @throws Exception
     */
    @PostMapping("/sendMailLink")
    public RespBean sendMailLink(@RequestParam("to") String to, @RequestParam("url") String url) throws Exception {
        boolean bool = mailService.sendHtmlLink(to, url);
        return RespBean.ok(null, bool);
    }
}